package com.alinesno.cloud.portal.desktop.web.plugins;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.alinesno.cloud.common.web.base.advice.TranslateCode;
import com.alinesno.cloud.common.web.base.advice.TranslatePlugin;
import com.alinesno.cloud.portal.desktop.web.entity.ModuleEntity;
import com.alinesno.cloud.portal.desktop.web.service.IModuleService;

/**
 * 文章内容转换
 * @author WeiXiaoJin
 * @since 2019年4月7日 下午10:04:58
 */
@Component("moduleTranslatePlugin")
public class ModuleTranslatePlugin implements TranslatePlugin {

	@Autowired
	private IModuleService moduleService ; 
	
	private String MODULEPARENTID = "moduleParentId" ; 
	
	@Override
	public void translate(JSONObject node, TranslateCode convertCode) {
		Object typeNode = node.get(MODULEPARENTID) ; 
		
		String value = "" ; 
		if(typeNode != null) {
			log.debug("type node = {}" , typeNode.toString());
			if(StringUtils.isNotBlank(typeNode.toString())) {
				ModuleEntity dto = moduleService.findEntityById(typeNode.toString()) ; // linkPathTypeService.findEntityBylinkTypeCode(typeNode.toString()) ; 
				value = dto != null? dto.getModuleName() : "父类" ;
			}
		}
		node.put(MODULEPARENTID + LABEL_SUFFER, value) ; 
	}

}
